// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias. 
import Vue from 'vue'
import App from './App'
import router from './router'
import { Header,Swipe, SwipeItem,Button,Switch } from 'mint-ui'
import 'mint-ui/lib/style.css'
import './mui.min.css'
import mui from './mui.min.js'    
import './icons-extra.css'  
import Vuex from 'vuex' 
import axios from 'axios'
import VueAxios from 'vue-axios' 

Vue.use(Vuex);
Vue.prototype.$http = axios;
var store = new Vuex.Store({
		state:{
			car:[]
		},
		mutations:{
			addToCar(state,goodsInfo){
				var flag = false
				state.car.some(item=>{if(item.id == goodsInfo.id){
					item.count+= parseInt(goodsInfo.count)
					flag = true
					return true
				}
				})
				if(!flag){
					state.car.push(goodsInfo)
				}
			},
			updateCarCount(state,goodsInfo){
				state.car.some(item=>{
					if(item.id == goodsInfo.id){
						item.count = parseInt(goodsInfo.count)
						return true
				
					}
				})
			},
			updateCarSelected(state,goodsInfo){
				state.car.some(item=>{
					if(item.id == goodsInfo.id){
						item.selected =goodsInfo.selected
						return true
					}
				})
			},
			removeCar(state,goodsInfo){
				state.car.some(
					(item,i)=>{
						if(item.id ==goodsInfo.id){
							state.car.splice(i,1)
							return true
						}
					})
			}
		},
		getters:{
			getAllCount(state){
				var c = 0
				state.car.forEach(item=>{
					c+=item.count
				})
			return c	
			},
			getSelectedCount(state){
			var o={count:0,price:0}
			state.car.forEach(item=>{
				if(item.selected){
					o.count +=item.count
					o.price +=parseInt(item.price.substr(1))*item.count
					
				}
			})
			return o
		}
		}
			
	});           
Vue.component(Header.name,Header);
Vue.component(Swipe.name,Swipe);
Vue.component(SwipeItem.name,SwipeItem);
Vue.component(Button.name,Button)
Vue.component(Switch.name, Switch);
Vue.config.productionTip = false
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>',
  store
})
window.mui = mui